package com.angysnail.guava.future;

import java.util.concurrent.Callable;
import java.util.concurrent.Executors;

import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
import com.google.common.util.concurrent.MoreExecutors;

public class ListenableFutureTest {
	private void test1() {
		ListeningExecutorService executorService = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(3));
		ListenableFuture<String> listenableFuture = executorService.submit(new Callable<String>() {

			@Override
			public String call() throws Exception {
				System.out.println(String.format("%s, %s", Thread.currentThread(), " is in the call method!"));
				return "callable called!";
			}

		});
		listenableFuture.addListener(() -> {
			System.out.println(String.format("%s, %s", Thread.currentThread(), ", and I know the call method called"));
		}, executorService);
	}

	public static void main(String[] args) {
		ListenableFutureTest test = new ListenableFutureTest();
		test.test1();
	}
}
